using System;
using System.Collections.Generic;
using Library;
using Library.Util;
using NHibernate;

namespace Library.Persistence.Cloud.Dao
{
	public class CloudFirmaKullaniciAjandaDao : BaseEntity
	{
		private readonly string fromHql = " from CloudFirmaKullaniciAjanda as t ";
		public void Insert(CloudFirmaKullaniciAjanda dto)
		{
			BasePersistence.Insert(dto);
		}

		public void Update(CloudFirmaKullaniciAjanda dto)
		{
			BasePersistence.Update(dto);
		}

		public void Delete(CloudFirmaKullaniciAjanda dto)
		{
			BasePersistence.Delete(dto);
		}

		public void Delete(int ajandaId)
		{
			CloudFirmaKullaniciAjanda dto = new CloudFirmaKullaniciAjanda();
			dto.AjandaId = ajandaId;
			Delete(dto);
		}

		public CloudFirmaKullaniciAjanda Get(int ajandaId, LockMode lockMode)
		{
			return Get<CloudFirmaKullaniciAjanda>(ajandaId, lockMode);
		}

		public List<CloudFirmaKullaniciAjanda> FindAll()
		{
			return Find<CloudFirmaKullaniciAjanda>(fromHql, LockMode.Read);
		}

		public List<CloudFirmaKullaniciAjanda> FindAll(string orderStatement)
		{
			return Find<CloudFirmaKullaniciAjanda>(fromHql + " ORDER BY " + orderStatement, LockMode.Read);
		}

		public List<CloudFirmaKullaniciAjanda> FindByKullaniciIdAndTarih(string kullaniciId, string baslangicTarih, string bitisTarih, LockMode lockMode)
		{
			string hql = fromHql;
			hql += @"WHERE 
t.KullaniciId = :kullaniciId AND (t.BaslangicTarih BETWEEN :baslangicTarih AND :bitisTarih OR t.BitisTarih BETWEEN :baslangicTarih AND :bitisTarih)";
			FinderParameter[] parameters = new FinderParameter[3];
			parameters[0] = new FinderParameter("parameter", "kullaniciId", kullaniciId);
			parameters[1] = new FinderParameter("parameter", "baslangicTarih", baslangicTarih);
			parameters[2] = new FinderParameter("parameter", "bitisTarih", bitisTarih);
			return Find<CloudFirmaKullaniciAjanda>(hql, parameters, lockMode);
		}

	}
}
